﻿using NUnit.Framework;
using StoryQ;
using TripleA.StoryQ;

namespace TripleA.Tests.Database
{
    [TestFixture]
    public class RunQueryTests : BddFeature
    {
        protected override Feature DescribeFeature()
        {
            return new Story("Testing the database run query extension")
                .InOrderTo("Run sql queries")
                .AsA("system test")
                .IWant("triplea to manage this for me");
        }

        [Test]
        public void ExplicitNamedConnection()
        {
            using (var domain = new DatabaseDomain())
            {
                Feature.WithScenario("Running a valid query with a named connection string")
                    .Given(domain.TheDefaultValidSqlCommandIsUsed)
                    .And(domain.TheConnectionNameIs_, "TripleA")
                    .When(domain.TheRunQueryStepIsCalled)
                    .Then(domain.ThrewNoException)
                    .ExecuteWithReport();
            }
        }

        [Test]
        public void ConnectionSetInAppConfig()
        {
            using (var domain = new DatabaseDomain())
            {

                Feature.WithScenario("Running a query using the default sql connection app.config setting")
                    .Given(domain.TheDefaultValidSqlCommandIsUsed)
                    .And(domain.TheDefaultConnectionAppSettingIsUsed)
                    .When(domain.TheRunQueryStepIsCalled)
                    .Then(domain.ThrewNoException)
                    .ExecuteWithReport();
            }
        }
    }
}